



import 'package:easeim_flutter_demo/pages/chat/chat_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:huajianshe_app/pages/auth/LoginPage.dart';
import 'package:huajianshe_app/pages/circle/CircleCreatePage.dart';
import 'package:huajianshe_app/pages/circle/CircleDetailPage.dart';
import 'package:huajianshe_app/pages/circle/CircleEditPage.dart';
import 'package:huajianshe_app/pages/circle/CircleListPageWithAppBar.dart';
import 'package:huajianshe_app/pages/circle/CircleManagementPage.dart';
import 'package:huajianshe_app/pages/circle/JointCirclesPage.dart';
import 'package:huajianshe_app/pages/circle/LinkCirclesPage.dart';
import 'package:huajianshe_app/pages/contact/ContactPage.dart';
import 'package:huajianshe_app/pages/contact/MemberManagementPage.dart';
import 'package:huajianshe_app/pages/lesson/LessonDetailPage.dart';
import 'package:huajianshe_app/pages/lesson/LessonListPageWithAppBar.dart';
import 'package:huajianshe_app/pages/lesson/LessonSpecialListPage.dart';
import 'package:huajianshe_app/pages/lesson/MyLessonsPage.dart';
import 'package:huajianshe_app/pages/lesson/PayPage.dart';
import 'package:huajianshe_app/pages/main/MainPage.dart';
import 'package:huajianshe_app/pages/main/PostPage.dart';
import 'package:huajianshe_app/pages/main/PrePostPage.dart';
import 'package:huajianshe_app/pages/mine/ImportFriendPage.dart';
import 'package:huajianshe_app/pages/mine/MinePage.dart';
import 'package:huajianshe_app/pages/mine/MyMomentsPage.dart';
import 'package:huajianshe_app/pages/mine/SettingPage.dart';
import 'package:huajianshe_app/pages/mine/UserInfoEditPage.dart';
import 'package:huajianshe_app/pages/search/SearchPage.dart';
import 'package:huajianshe_app/pages/splash.dart';
import 'package:huajianshe_app/pages/user_info/LabelListPage.dart';
import 'package:huajianshe_app/pages/user_info/LabelSettingPage.dart';
import 'package:huajianshe_app/pages/user_info/UserInfoPage.dart';
import 'package:huajianshe_app/pages/user_info/UserMomentsPage.dart';
import 'package:huajianshe_app/widget/ImageViewerWidget.dart';
import 'package:huajianshe_app/widget/VideoPlayerWidget.dart';


class AppRouter {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    print('route: ${settings.name}');
    final Map<String, dynamic>? arguments = settings.arguments is Map ? Map<String, dynamic>.from(settings.arguments as Map) : null;
    Widget page = getPage(settings.name, arguments) //pagesMap[settings.name]
        ?? Scaffold(
      body: Center(
        child: Text('No route defined for ${settings.name}'),
      ),
    );
    return NoAnimRouteBuilder(page);
  }

  static Map<String, Widget> pagesMap = {
    RouteName.SPLASH: SplashPage(),
    RouteName.LOGIN: LoginPage(),
    RouteName.MAIN: MainPage(),
    RouteName.MINE: MinePage(),
    // RouteName.USER_INFO: UserInfoPage()
  };

  static Widget? getPage(String? name, Map<String, dynamic>? arguments) {
    switch(name) {
      case RouteName.SPLASH: return SplashPage();
      case RouteName.LOGIN: return LoginPage();
      case RouteName.MAIN: return MainPage();
      case RouteName.MINE: return MinePage();
      case RouteName.USER_INFO: return UserInfoPage(arguments?['userInfo'], circleInfo: arguments?['circleInfo']);
      case RouteName.USER_MOMENTS: return UserMomentsPage(momentType: arguments?['momentType'],
        userInfo: arguments?['userInfo'], circleInfo: arguments?['circleInfo'],);
      case RouteName.PREPOST: return PrePostPage();
      case RouteName.POST: return PostPage(arguments?['type'], arguments?['joined'], arguments?['created']);
      case RouteName.LINK_CIRCLES: return LinkCirclesPage(arguments?['joined'], arguments?['created'], arguments?['selected']);
      case RouteName.JOINT_CIRCLES: return JointCirclesPage(circles: arguments?['circles']);
      case RouteName.SEARCH: return SearchPage(arguments?['searchType'], momentType: arguments?['momentType'], circleId: arguments?['circleId'], businessType: arguments?['businessType'],);
      case RouteName.CIRCLE_DETAIL: return CircleDetailPage(arguments?['circleDetailType'], arguments?['circleId'], circleDetailData: arguments?['circleDetailData'],);
      case RouteName.CIRCLE_MANAGEMENT: return CircleManagementPage(arguments?['circleId'], arguments?['name'], arguments?['viewNum'], arguments?['score'], arguments?['importUrl']);
      case RouteName.CIRCLE_CREATE: return CircleCreatePage();
      case RouteName.PAY: return PayPage(arguments?['url'], arguments?['title'], arguments?['desc'], arguments?['price']);
      case RouteName.LESSON_DETAIL: return LessonDetailPage(arguments?['id']);
      case RouteName.VIDEO_PLAYER: return VideoPlayerWidget(arguments?['url']);
      case RouteName.MY_LESSONS: return MyLessonsPage();
      case RouteName.LESSON_LIST: return LessonListPageWithAppBar(arguments?['id'], arguments?['title'], type: arguments?['type'],
        recommendStatus: arguments?['recommendStatus'], isNewSale: arguments?['isNewSale']);
      case RouteName.SPECIAL_LESSON_LIST: return LessonSpecialListPage(arguments?['id'], arguments?['title'], type: arguments?['type'],
          recommendStatus: arguments?['recommendStatus'], isNewSale: arguments?['isNewSale']);
      case RouteName.IMAGE_VIEWER: return ImageViewerWidget(arguments?['urls'], index: arguments?['index']);
      case RouteName.CHAT: return ChatPage(arguments?['id'], arguments?['conv']);
      case RouteName.MEMBER_MANAGEMENT: return MemberManagementPage(arguments?['circleId']);
      case RouteName.CIRCLE_MORE: return CircleListPageWithAppBar(arguments?['type'], arguments?['title']);
      case RouteName.CIRCLE_EDIT: return CircleEditPage(arguments?['circleId']);
      case RouteName.CIRCLE_ADD_MEMBER: return ImportFriendPage(arguments?['circleId'], arguments?['importUrl']);
      case RouteName.USER_INFO_EDIT: return UserInfoEditPage(arguments?['userInfo']);
      case RouteName.MY_CONTACT: return ContactPage();
      case RouteName.MY_MOMENTS: return MyMomentsPage();
      case RouteName.SETTING: return SettingPage();
      case RouteName.LABEL_SETTING: return LabelSettingPage(arguments?['memberSn']);
      case RouteName.LABEL_LIST: return LabelListPage();
    }
  }
}

class RouteName {
  static const String LOGIN = '/login';
  static const String MAIN = '/main';
  static const String SPLASH = '/';
  static const String MINE = '/mine';
  static const String USER_INFO = '/user_info';
  static const String USER_MOMENTS = '/user_moments'; //查看用户所有动态
  static const String PREPOST = '/prepost'; // 选择发布页
  static const String POST = '/post'; //发布
  static const String LINK_CIRCLES = '/link_circles'; //关联圈子
  static const String JOINT_CIRCLES = '/joint_circles'; //共同的圈子
  static const String SEARCH = '/search'; //公共搜索页
  static const String CIRCLE_DETAIL = '/circle_detail'; //圈子详情
  static const String CIRCLE_MANAGEMENT = '/circle_management';//圈子管理
  static const String CIRCLE_CREATE = '/circle_create'; //圈子创建
  static const String PAY = '/pay'; //支付
  static const String LESSON_DETAIL = '/lesson_detail'; //课程详情
  static const String VIDEO_PLAYER = '/video_player'; //视频播放
  static const String MY_LESSONS = '/my_lessons'; //我的课程
  static const String LESSON_LIST = '/lesson_list'; //各种课程列表（带appbar）
  static const String SPECIAL_LESSON_LIST = '/special_lesson_list'; // 课程专栏
  static const String IMAGE_VIEWER = '/image_viewer'; //查看图片
  static const String MEMBER_MANAGEMENT = '/member_management'; //成员管理
  static const String CIRCLE_MORE = '/circle_more'; //圈子首页里的更多
  static const String CIRCLE_EDIT = '/circle_edit'; //圈子设置、编辑
  static const String CIRCLE_ADD_MEMBER = '/circle_add_member'; //导入一个成员
  static const String SETTING = '/setting'; //系统设置
  static const String USER_INFO_EDIT = '/user_info_edit'; //编辑个人信息
  static const String MY_CONTACT = '/my_contact'; //人脉首页兼我的好友页
  static const String MY_MOMENTS = '/my_moments'; //我的动态
  static const String LABEL_SETTING = '/label_setting';//设置备注和标签
  static const String LABEL_LIST = '/label_list';//标签列表

  static const String CHAT = '/chat'; //单聊
}

class NoAnimRouteBuilder extends PageRouteBuilder {
  final Widget page;

  NoAnimRouteBuilder(this.page) : super(
      opaque: false,
      pageBuilder: (context, animation, secondaryAnimation) => page,
      transitionDuration: Duration(milliseconds: 0),
      transitionsBuilder:
          (context, animation, secondaryAnimation, child) => child);
}